home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-14 | 8.4 KB | 341 lines | [TEXT/KAHL] |
- /******************************************************************************
- CTableLabels.h
-
- A subclass of CTable that is used to display row or column labels
- for another CTable.
-
- SUPERCLASS = CTable
-
- Copyright © 1991 Symantec Corporation. All rights reserved.
-
-
- ******************************************************************************/
-
- #include "CTableLabels.h"
- #include "CTableScroller.h"
- #include "CTable.h"
- #include "CRowColSizer.h"
- #include "CRunArray.h"
- #include "CPaneBorder.h"
- #include "Packages.h"
-
- #define kGrowColCursor 1025 // resize column cursor ID
- #define kGrowRowCursor 1026 // resize row column cursor ID
-
- #define kSlopAmount 3 // slop amount in pixels for recognizing
- // row or column border clicks
-
- /******************************************************************************
- ITableLabels
-
- Initialization method for CTableLabels. aTblScroller is a subclass of
- CScrollPane that aids in synchronizing the scrolling of the table and
- labels. rowsOrCols indicates what type of labels this table is to
- display. size is the desired height of row labels or desired width of
- column labels. anOffset is a horizontal or vertical offset needed
- to line the labels up with the table.
- ******************************************************************************/
-
- void CTableLabels::ITableLabels(CTableScroller *aTblScroller, VHSelect rowsOrCols,
- short size, short anOffset)
- {
- Rect delta;
-
- itsTable = NULL;
-
- whichDimension = rowsOrCols;
-
- SetRect(&delta, 0, 0, 0, 0);
-
- if (whichDimension == h) /* column labels */
- {
- CTable::ITable(aTblScroller, aTblScroller, 0, size, 0, 0,
- sizELASTIC, sizFIXEDTOP);
- FitToEnclosure(kDoHorizontal, kNotVertical);
- Offset(anOffset, 0, kNoRedraw);
- delta.right = -anOffset;
- }
- else /* row labels */
- {
- CTable::ITable(aTblScroller, aTblScroller, size, 0, 0, 0,
- sizFIXEDLEFT, sizELASTIC);
- FitToEnclosure(kNotHorizontal, kDoVertical);
- Offset(0, anOffset, kNoRedraw);
- delta.bottom = -anOffset;
- }
- ChangeSize(&delta, kNoRedraw);
-
- ITableLabelsX();
- }
-
- /******************************************************************************
- ITableLabelsX
-
- Extra initialization for CTableLabels. Fills in additional instance
- variables, and border.
- ******************************************************************************/
-
- void CTableLabels::ITableLabelsX(void)
- {
- short cursID;
- short borderFlags;
-
- SetCanBeGopher(FALSE);
- SetSelectionFlags(selDragRects);
- textStyle = bold;
- initiatedNewSelection = FALSE;
-
- if (whichDimension == h)
- {
- cursID = kGrowColCursor;
- drawOrder = tblRow;
- AddRow(1, -1);
- SetColBorders(1, patCopy, &qd.black);
- borderFlags = kBorderBottom;
- }
- else
- {
- cursID = kGrowRowCursor;
- drawOrder = tblCol;
- AddCol(1, -1);
- SetRowBorders(1, patCopy, &qd.black);
- borderFlags = kBorderRight;
- }
-
- itsBorder = new(CPaneBorder);
- itsBorder->IPaneBorder(borderFlags);
-
- growCursor = GetCursor(cursID);
- FailNILRes(growCursor);
-
- }
-
- /******************************************************************************
- ~CTableLabels
-
- Since CTableLabels shares either the row or column size array with
- its table, we must ensure that the shared array is not disposed when
- the table labels are disposed.
- ******************************************************************************/
-
- CTableLabels::~CTableLabels(void)
- {
- /* don't dispose of objects owned by itsTable */
- if (itsTable)
- {
- if (whichDimension == h)
- itsCols = NULL;
- else
- itsRows = NULL;
- }
- }
-
- /******************************************************************************
- SetTable
-
- Specify the table for which this object is to provide labels. CTableLabels
- shares the row or column size array with itsTable. This ensures that
- both tables have the same number of rows or columns with the same dimensions.
- ******************************************************************************/
-
- void CTableLabels::SetTable(CTable *aTable)
- {
- itsTable = aTable;
- if (whichDimension == h)
- {
- ForgetObject(itsCols);
- itsCols = ((CTableLabels*)itsTable)->itsCols;
- DependUpon(itsCols);
- SetRowHeight(0, height);
- }
- else
- {
- ForgetObject(itsRows);
- itsRows = ((CTableLabels*)itsTable)->itsRows;
- DependUpon(itsRows);
- SetColWidth(0, width);
- }
- DependUpon(itsTable);
- }
-
- /******************************************************************************
- Draw {OVERRIDE}
-
- This method does some setup before drawing the labels. It restores the
- drawing environment of itsTable, to ensure the both draw with the
- same environment.
- ******************************************************************************/
-
- void CTableLabels::Draw(Rect *area)
- {
- ASSERT(itsTable != NULL);
-
- itsTable->RestoreEnvironment();
- TextFace(textStyle);
-
- tblIndent = ((CTableLabels*)itsTable)->indent;
-
- inherited::Draw(area);
- }
-
- /******************************************************************************
- DrawCell {OVERRIDE}
-
- Draw the row or column number.
- ******************************************************************************/
-
- void CTableLabels::DrawCell(Cell theCell, Rect *cellRect)
- {
- Str31 numBuf;
- short val;
- short sWidth;
-
-
- val = (whichDimension == h)? theCell.h : theCell.v;
- val++;
-
- NumToString(val, numBuf);
- sWidth = StringWidth(numBuf);
-
- MoveTo(cellRect->left + (cellRect->right - cellRect->left - sWidth)/2,
- cellRect->top + tblIndent.v);
-
- DrawString(numBuf);
-
- }
-
- /******************************************************************************
- GetHitBoundary
-
- Determine whether a point in Frame coordinates lies on a row or column
- boundary. This method is used both for hit testing clicks and for
- adjusting the cursor.
-
- ******************************************************************************/
-
- short CTableLabels::GetHitBoundary(LongPt *hitPt)
- {
- short boundary = -1, rowOrCol;
- long start, mouseLoc, diff;
-
- if (whichDimension == h)
- {
- mouseLoc = hitPt->h + kSlopAmount;
- rowOrCol = FindCol(mouseLoc);
- if ((rowOrCol >= 0) && (rowOrCol < tableBounds.right))
- {
- start = GetColStart(rowOrCol);
- }
- else rowOrCol = -1;
- }
- else
- {
- mouseLoc = hitPt->v + kSlopAmount;
- rowOrCol = FindRow(mouseLoc);
- if ((rowOrCol > 0) && (rowOrCol < tableBounds.bottom))
- {
- start = GetRowStart(rowOrCol);
- }
- else rowOrCol = -1;
- }
- diff = mouseLoc - start - kSlopAmount;
- if (Abs(diff) <= kSlopAmount)
- boundary = rowOrCol-1;
-
- return boundary;
- }
-
- /******************************************************************************
- DoClick
- ******************************************************************************/
-
- void CTableLabels::DoClick(Point hitPt, short modifierKeys, long when)
- {
- short boundary;
- LongPt framePt;
- CRowColSizer *sizeTask;
- LongRect limitRect;
-
- QDToFrame(hitPt, &framePt);
- boundary = GetHitBoundary(&framePt);
- if (boundary >= 0)
- {
- itsTable->GetInterior(&limitRect);
- sizeTask = new CRowColSizer(itsTable, this, boundary, whichDimension,
- &limitRect, 0);
-
- itsLastTask = sizeTask;
- itsTable->itsLastTask = sizeTask;
-
- FrameToWind(&framePt, &hitPt);
- itsTable->WindToFrame(hitPt, &framePt);
-
- itsTable->TrackMouse(sizeTask, &framePt, &limitRect);
-
- Notify(sizeTask);
- Refresh();
- }
- }
-
- /******************************************************************************
- AdjustCursor
- ******************************************************************************/
-
- void CTableLabels::AdjustCursor(Point where, RgnHandle mouseRgn)
- {
- short boundary;
- LongPt framePt;
- extern long gSleepTime;
-
- Prepare();
- WindToFrame(where, &framePt);
- boundary = GetHitBoundary(&framePt);
- if (boundary >= 0)
- {
- LoadResource((Handle) growCursor);
- if (*growCursor)
- SetCursor(*growCursor);
- }
- else
- SetCursor(&qd.arrow);
- gSleepTime = 0;
- }
-
- /******************************************************************************
- ProviderChanged
-
- ******************************************************************************/
-
- void CTableLabels::ProviderChanged(CCollaborator *aProvider,
- long reason, void* info)
- {
- short newSize = *(long*) info;
- Boolean changed = FALSE;
-
- if (reason == runArraySizeChanged)
- {
- if ((whichDimension == h) && (aProvider == itsCols))
- {
- tableBounds.right = newSize;
- changed = TRUE;
- }
- else if (aProvider == itsRows)
- {
- tableBounds.bottom = newSize;
- changed = TRUE;
- }
- if (changed)
- {
- AdjustBounds();
- Refresh();
- }
- }
- else if (reason == runArrayElementChanged) // TCL 1.1.3 11/18/92
- {
- AdjustBounds();
- Refresh();
- }
- else
- inherited::ProviderChanged(aProvider, reason, info);
- }
-